package com.ruoyi.project.user.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.user.domain.BinsViolationRecord;
import com.ruoyi.project.user.service.IBinsViolationRecordService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 违规记录Controller
 * 
 * @author administrator
 * @date 2025-04-03
 */
@RestController
@RequestMapping("/user/violation")
public class BinsViolationRecordController extends BaseController
{
    @Autowired
    private IBinsViolationRecordService binsViolationRecordService;

    /**
     * 查询违规记录列表
     */
    @PreAuthorize("@ss.hasPermi('user:violation:list')")
    @GetMapping("/list")
    public TableDataInfo list(BinsViolationRecord binsViolationRecord)
    {
        startPage();
        List<BinsViolationRecord> list = binsViolationRecordService.selectBinsViolationRecordList(binsViolationRecord);
        return getDataTable(list);
    }

    /**
     * 导出违规记录列表
     */
    @PreAuthorize("@ss.hasPermi('user:violation:export')")
    @Log(title = "违规记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BinsViolationRecord binsViolationRecord)
    {
        List<BinsViolationRecord> list = binsViolationRecordService.selectBinsViolationRecordList(binsViolationRecord);
        ExcelUtil<BinsViolationRecord> util = new ExcelUtil<BinsViolationRecord>(BinsViolationRecord.class);
        util.exportExcel(response, list, "违规记录数据");
    }

    /**
     * 获取违规记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('user:violation:query')")
    @GetMapping(value = "/{violationId}")
    public AjaxResult getInfo(@PathVariable("violationId") Long violationId)
    {
        return success(binsViolationRecordService.selectBinsViolationRecordByViolationId(violationId));
    }

    /**
     * 新增违规记录
     */
    @PreAuthorize("@ss.hasPermi('user:violation:add')")
    @Log(title = "违规记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BinsViolationRecord binsViolationRecord)
    {
        return toAjax(binsViolationRecordService.insertBinsViolationRecord(binsViolationRecord));
    }

    /**
     * 修改违规记录
     */
    @PreAuthorize("@ss.hasPermi('user:violation:edit')")
    @Log(title = "违规记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BinsViolationRecord binsViolationRecord)
    {
        return toAjax(binsViolationRecordService.updateBinsViolationRecord(binsViolationRecord));
    }

    /**
     * 删除违规记录
     */
    @PreAuthorize("@ss.hasPermi('user:violation:remove')")
    @Log(title = "违规记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{violationIds}")
    public AjaxResult remove(@PathVariable Long[] violationIds)
    {
        return toAjax(binsViolationRecordService.deleteBinsViolationRecordByViolationIds(violationIds));
    }
}
